<?php
namespace app\admin\model;

use think\Exception;
use think\facade\Request;
use think\Model;
use think\model\concern\SoftDelete;

class AuthRule extends Model{
    protected $pk='id';
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    //首页循环
     public static function   authRuleList(){
         $find=AuthGroupAccess::authGroupAccessInfo();
         $find['rules']=explode(',',$find['rules']);
         $list=AuthRule::where('if_show','=',1)
             ->where('id','in', $find['rules'])
             ->select();
         return $list;
     }
    //获取器  是否显示变图片显示
    public static function   getIfShowImgAttr($v,$data){
        if ($data['if_show']==1){
            return "<img src='/static/images/√.jpg' width='70' height='50'/>";
        }else{
            return "<img src='/static/images/X.jpg'  width='70' height='50' />";
        }
    }
    //获取器   是否有效变图片显示
    public static function   getStatusImgAttr($v,$data){
        if ($data['status']==1){
            return "<img src='/static/images/√.jpg' width='70' height='50'/>";
        }else{
            return "<img src='/static/images/X.jpg'  width='70' height='50' />";
        }
    }

    //权限列表展示
     public static function   authListInfo(){
         $list=AuthRule::where('pid','=','0')
             ->select();
         return $list;

     }

     //权限列表添加
     public static function   authAddInfo($post){
       try{
         $res=AuthRule::insert($post);
       }catch (Exception $e){
           $res=false;
       }
        return $res;
     }

     //权限列表修改
     public static function   authEditInfo($param){
         if (Request::isPost()){
             try{
                $res=AuthRule::update($param);
             }catch (Exception $e){
                 $res=false;
             }
                 return $res;
         }else{
             $find=AuthRule::find($param['id']);
             return $find;
         }
         }


     //权限列表修改
     public static function    authDelInfo($get){
         try{
             $res=AuthRule::destroy($get['id']);
         }catch (Exception $e){
             $res=false;
         }
           return $res;
         }

}